Package com.apps.outgoing

Source Code of com.apps.outgoing.AccountActivation

/*
* AUTHOR: Kevin Lam
*/


package com.apps.outgoing;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.apps.utils.EmailUtils;

public class AccountActivation {

  private Properties p;
  private Session s;

  public AccountActivation() {
    p = new Properties();
    s = Session.getDefaultInstance(p, null);
  }
 


  public boolean sendVerification(String recipient, String authKey) {

    try {
      Message msg = new MimeMessage(s);
      msg.setFrom(new InternetAddress("noreply@ubc-cc.appspotmail.com",
          "UBC Course Companion"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
          recipient, recipient));
      msg.setSubject("New account verification");
      String body = EmailUtils.getVerificationMessageBody(recipient, authKey);
      msg.setText(body);
      Transport.send(msg);

    } catch (AddressException e1) {
      e1.printStackTrace();
      return false;
    } catch (MessagingException e2) {
      e2.printStackTrace();
      return false;
    } catch (UnsupportedEncodingException e3) {
      e3.printStackTrace();
      return false;
    }
    return true;
  }
}
TOP

Related Classes of com.apps.outgoing.AccountActivation

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.